package com.xht.runner;

import com.xht.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class TestRunner implements CommandLineRunner {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Autowired
    private ArticleService articleService;

    /**
     * 在所有bean初始化后,便会执行
     *
     * @param args
     * @throws Exception
     */
    @Override
    public void run(String... args) throws Exception {
//        //在应用启动时把博客的浏览量存储到redis中 --redis预加载
//        List<Article> articleList = articleService.list();
//
//        //将 文章浏览量 存储到 redis 上
//        stringRedisTemplate.opsForValue().set(SystemConstants.VIEW_COUNT, JSONUtil.toJsonStr(articleList));
//        System.out.println("程序初始化!!!");
    }
}
